package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"net/http"
)

const url = "http://localhost:8545"

func main() {
	web3ClientVersion()
	EthAccounts()
}

func web3ClientVersion() {
	var msg = `{"jsonrpc":"2.0","method":"web3_clientVersion","id":222}`
	resp, err := http.Post(url, "application/json", bytes.NewBuffer([]byte(msg)))
	assert(err)
	ret, err := ioutil.ReadAll(resp.Body)
	assert(err)
	fmt.Println("web3_clientVersion: ", string(ret))
}

func EthAccounts() {
	var msg = `{"jsonrpc":"2.0","method":"eth_accounts","id":222}`
	resp, err := http.Post(url, "application/json", bytes.NewBuffer([]byte(msg)))
	assert(err)
	ret, err := ioutil.ReadAll(resp.Body)
	assert(err)
	fmt.Println("eth_accounts: ", string(ret))
}

func assert(err error) {
	if err != nil {
		fmt.Println(err)
		panic(err)
	}
}
